package cn.edu.tju.elm.repository;

import cn.edu.tju.core.model.User;
import cn.edu.tju.elm.model.entity.VirtualWallet;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface VirtualWalletRepository extends JpaRepository<VirtualWallet, Long> {

    Optional<VirtualWallet> findByUser(User user);

    Optional<VirtualWallet> findByUserId(Long userId);

    @Query("SELECT w FROM VirtualWallet w WHERE w.user.id = :userId AND w.deleted = false")
    Optional<VirtualWallet> findActiveByUserId(@Param("userId") Long userId);

    boolean existsByUserId(Long userId);
}